﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Com.BU;
using Com.DA;

namespace ThermalEquipmentDesign.Model.Condenser.CoolAirR22
{
    public class CoolAirR22 : ObservableObject
    {
        // Declare fields for inputting
        #region Feild Input
        private double dbcoldProductivity;
        private double dbairTemp;
        private double dbcondensationTemp;
        private double dbheatCapacityPerform;
        private double dbinterDiameter = 0.021;
        private double dboriginalDiameter = 0.028;
        private double dbvaneDiameter = 0.049;
        private double dboutVaneArea = 0.79;
        private double dbfinPitch = 0.0035;
        private double dbvaneThickness = 0.0006;
        private double dbhorizontalFinPitch = 0.052;
        private double dbverticalFinPitch = 0.045;
        private double dbdiagonalFinPitch = 0.052;
        private double dbairDiffTemp = 8;
        private double dbheatCapacity;
        private double dbspecificQuantity;
        private double dbkinematicViscosity;
        private double dbheatConductCoefficient;
        private double dbairSpeed = 9;
        private double dbnCoefficient = 0.65;
        private double dbcCoefficient = 0.23;
        private double dbczCoefficient = 0.95;
        private double dbeCoefficient = 1;
        private double dbheatTransferCoefficient = 0.85;
        private double dbsteelThickness = 0.002;
        private double dbsteelHeatTransferCoefficient = 45.3;
        private double dbaluThickness = 0.0015;
        private double dbaluHeatTransferCoefficient = 203.5;
        private double dbdiffTemp = 2.9;
        private double dbpipeLenght = 3;
        private double dbairPipeNume = 4;
        #endregion

        // Create properties for fields
        #region Properties Input
        public double dbColdProductivity
        {
            get { return dbcoldProductivity; }
            set
            {
                if (value != dbcoldProductivity)
                {
                    dbcoldProductivity = value;
                    OnPropertyChanged("dbColdProductivity");
                }
            }
        }

        public double dbAirTemp
        {
            get { return dbairTemp; }
            set
            {
                if (value != dbairTemp)
                {
                    dbairTemp = value;
                    SetAverageTemp();
                    OnPropertyChanged("dbAirTemp");
                }
            }
        }

        public double dbCondensationTemp
        {
            get { return dbcondensationTemp; }
            set { dbcondensationTemp = value; }
        }

        public double dbHeatCapacityPerform
        {
            get { return dbheatCapacityPerform; }
            set { dbheatCapacityPerform = value; }
        }

        public double dbInterDiameter
        {
            get { return dbinterDiameter; }
            set { dbinterDiameter = value; }
        }

        public double dbOriginalDiameter
        {
            get { return dboriginalDiameter; }
            set { dboriginalDiameter = value; }
        }

        public double dbVaneDiameter
        {
            get { return dbvaneDiameter; }
            set { dbvaneDiameter = value; }
        }

        public double dbOutVaneArea
        {
            get { return dboutVaneArea; }
            set { dboutVaneArea = value; }
        }

        public double dbFinPitch
        {
            get { return dbfinPitch; }
            set { dbfinPitch = value; }
        }

        public double dbVaneThickness
        {
            get { return dbvaneThickness; }
            set { dbvaneThickness = value; }
        }

        public double dbHorizontalFinPitch
        {
            get { return dbhorizontalFinPitch; }
            set { dbhorizontalFinPitch = value; }
        }

        public double dbVerticalFinPitch
        {
            get { return dbverticalFinPitch; }
            set { dbverticalFinPitch = value; }
        }

        public double dbDiagonalFinPitch
        {
            get { return dbdiagonalFinPitch; }
            set { dbdiagonalFinPitch = value; }
        }

        public double dbAirDiffTemp
        {
            get { return dbairDiffTemp; }
            set
            {
                if (value != dbairDiffTemp)
                {
                    dbairDiffTemp = value;
                    SetAverageTemp();
                    OnPropertyChanged("dbAirDiffTemp");
                }
            }

        }

        public double dbHeatCapacity
        {
            get { return dbheatCapacity; }
            set
            {
                if (value != dbheatCapacity)
                {
                    dbheatCapacity = value;
                    OnPropertyChanged("dbHeatCapacity");
                }
            }
        }

        public double dbSpecificQuantity
        {
            get { return dbspecificQuantity; }
            set { dbspecificQuantity = value; }
        }

        public double dbKinematicViscosity
        {
            get { return dbkinematicViscosity; }
            set { dbkinematicViscosity = value; }
        }

        public double dbHeatConductCoefficient
        {
            get { return dbheatConductCoefficient; }
            set { dbheatConductCoefficient = value; }
        }

        public double dbAirSpeed
        {
            get { return dbairSpeed; }
            set { dbairSpeed = value; }
        }

        public double dbNCoefficient
        {
            get { return dbnCoefficient; }
            set { dbnCoefficient = value; }
        }

        public double dbCCoefficient
        {
            get { return dbcCoefficient; }
            set { dbcCoefficient = value; }
        }

        public double dbCzCoefficient
        {
            get { return dbczCoefficient; }
            set { dbczCoefficient = value; }
        }

        public double dbECoefficient
        {
            get { return dbeCoefficient; }
            set { dbeCoefficient = value; }
        }

        public double dbHeatTransferCoefficient
        {
            get { return dbheatTransferCoefficient; }
            set { dbheatTransferCoefficient = value; }
        }

        public double dbSteelThickness
        {
            get { return dbsteelThickness; }
            set { dbsteelThickness = value; }
        }

        public double dbSteelHeatTransferCoefficient
        {
            get { return dbsteelHeatTransferCoefficient; }
            set { dbsteelHeatTransferCoefficient = value; }
        }

        public double dbAluThickness
        {
            get { return dbaluThickness; }
            set { dbaluThickness = value; }
        }

        public double dbAluHeatTransferCoefficient
        {
            get { return dbaluHeatTransferCoefficient; }
            set { dbaluHeatTransferCoefficient = value; }
        }

        public double dbDiffTemp
        {
            get { return dbdiffTemp; }
            set { dbdiffTemp = value; }
        }

        public double dbPipeLenght
        {
            get { return dbpipeLenght; }
            set { dbpipeLenght = value; }
        }

        public double dbAirPipeNume
        {
            get { return dbairPipeNume; }
            set { dbairPipeNume = value; }
        }
        #endregion

        /// <summary>
        /// Change value foe properties that realted with average temperature
        /// </summary>
        private void SetAverageTemp()
        {
            double dbaverageTemp = (2 * dbairTemp + dbairDiffTemp) * 0.5;
            tb_water_coefficients watercoefficients = LibraryManagerInCom.WaterCoefficientsList.SingleOrDefault(w => w.Temperature == dbaverageTemp);
            if (watercoefficients != null)
            {
                dbheatCapacity = (double)watercoefficients.HeatSpecific;
                dbspecificQuantity = dbaverageTemp;
                dbkinematicViscosity = (double)watercoefficients.KinematicViscosity;
                dbheatConductCoefficient = (double)watercoefficients.HeatConductivity;
                OnPropertyChanged("dbHeatCapacity");
                OnPropertyChanged("dbSpecificQuantity");
                OnPropertyChanged("dbKinematicViscosity");
                OnPropertyChanged("dbHeatConductCoefficient");
            }
        }
    }
}
